home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr25 / stdapp.zip / UTL.C < prev    next >
Text File  |  1993-03-05  |  6KB  |  252 lines

  1. #define  INCL_PM
  2.  
  3. #include <os2.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include "utl.h"
  7.  
  8.  
  9. BOOL APIENTRY
  10. UtlDisplayError(HAB hab, PSZ pszString)
  11. {
  12.  
  13.   CHAR      szBuffer[80];
  14.   LONG      errid;
  15.   SHORT     sOS2Rc    = 0;
  16.   PSHORT    psOS2Rc;
  17.   PSZ       pszErrMsg = "";
  18.   PSHORT    psOffset;
  19.   PERRINFO  perriInfo = (PERRINFO)0;
  20.   PSZ       pszTitle;
  21.  
  22.   // Based on code found in on Winn - OS/2 PM GPI
  23.  
  24.   // get last error
  25.   errid = WinGetLastError(hab);
  26.  
  27.  
  28.   // if last error anything but PMERR_OK display the message box
  29.   if (ERRORIDERROR(errid) != PMERR_OK)
  30.   {
  31.  
  32.      // get error info
  33.  
  34.      perriInfo = WinGetErrorInfo(hab);
  35.  
  36.      // get PM error message pointer
  37.  
  38.      psOffset = MAKEP( SELECTOROF(perriInfo)
  39.                      , (perriInfo->offaoffszMsg +
  40.                         OFFSETOF(perriInfo)));
  41.  
  42.      pszErrMsg = MAKEP( SELECTOROF(perriInfo)
  43.                       , (*psOffset + OFFSETOF(perriInfo)));
  44.  
  45.      // if error code is PMERR_BASE_ERROR get base OS/2 error code
  46.  
  47.      if (ERRORIDERROR(errid) == PMERR_BASE_ERROR)
  48.      {
  49.         psOS2Rc = MAKEP( SELECTOROF(perriInfo)
  50.                        , (perriInfo->offBinaryData +
  51.                           OFFSETOF(perriInfo)));
  52.  
  53.         sOS2Rc  = *psOS2Rc;
  54.  
  55.         // format the message string
  56.         sprintf( szBuffer,"%x/%x/%d/%s %s\n"
  57.                , ERRORIDERROR(errid) // PM error code
  58.                , ERRORIDSEV(errid)   // severity
  59.                , sOS2Rc              // base OS/2 error number
  60.                , pszErrMsg           // PM error message
  61.                , pszString);         // callers string
  62.  
  63.         // message box title
  64.         pszTitle = "Error/Severity/OS2RC";
  65.      }
  66.      else // format the message string
  67.      {
  68.         sprintf( szBuffer,"%x/%x/ %s\n%s"
  69.                , ERRORIDERROR(errid)    // PM error code
  70.                , ERRORIDSEV(errid)      // severity
  71.                , pszErrMsg              // PM error message
  72.                , pszString);            // callers string
  73.  
  74.          // message box title
  75.          pszTitle = "Error/Severity";
  76.      }
  77.   }
  78.  
  79.  
  80.  
  81.   // display the error
  82.  
  83.   WinMessageBox( HWND_DESKTOP   // parent window
  84.                , (HWND)0        // owner window
  85.                , szBuffer       // message text
  86.                , pszTitle       // message box title
  87.                , 1              // message box id
  88.                , MB_CUACRITICAL // window style
  89.                | MB_SYSTEMMODAL
  90.                | MB_ENTER
  91.                );
  92.  
  93.   // free the error info
  94.  
  95.   if (perriInfo)
  96.     WinFreeErrorInfo(perriInfo);
  97.  
  98.   return API_FAILED;
  99. }  // End  UtlDisplayError()
  100.  
  101.  
  102.  
  103.  
  104. BOOL APIENTRY
  105. UtlLoadString( HAB hab, HMODULE hmod, USHORT usMsgID,
  106.                USHORT usSize, PSZ pszBuffer)
  107. {
  108.  
  109.    if (!WinLoadString(hab, hmod, usMsgID, usSize, pszBuffer))
  110.    {
  111.       UtlUserMsgBox( "Failed to load string."
  112.                    , "Ult.c"
  113.                    , MB_ENTER|MB_ERROR
  114.                    , TRUE
  115.                    , 0 );
  116.  
  117.       return API_FAILED;
  118.    }
  119.  
  120.    return API_SUCCESS;
  121.  
  122. }  // End of UtlLoadString()
  123.  
  124.  
  125. BOOL APIENTRY
  126. UtlLoadMessage(HAB hab, HMODULE hmod, USHORT usMsgID,
  127.                USHORT usSize, PSZ pszBuffer)
  128. {
  129.  
  130.    if (!WinLoadMessage(hab, hmod, usMsgID, usSize, pszBuffer))
  131.    {
  132.  
  133.       UtlUserMsgBox( "Failed to load message."
  134.                    , "Ult.c"
  135.                    , MB_ENTER|MB_ERROR
  136.                    , TRUE
  137.                    , 0 );
  138.  
  139.       return API_FAILED;
  140.    }
  141.  
  142.    return API_SUCCESS;
  143.  
  144. }   // End of UtlLoadMessage()
  145.  
  146.  
  147. PSZ APIENTRY
  148. UtlSubsitiuteStrings( HAB hab, HMODULE hmod, USHORT usMsgID, PSZ szTarget,
  149.                       PSZ szSub1)
  150. {
  151.   PSZ     pszReturnString = (PSZ)0;
  152.   CHAR    szFormat[UTLMAG_TEXT_LENGTH];
  153.   BOOL    fRc;
  154.  
  155.   fRc = UtlLoadMessage( hab
  156.                       , hmod
  157.                       , usMsgID
  158.                       , UTLMAG_TEXT_LENGTH
  159.                       , szFormat);
  160.  
  161.   if ( fRc == API_SUCCESS )
  162.   {
  163.      //sprintf(szTarget, szFormat, szSub1);
  164.      strcpy(szTarget, szFormat);
  165.      strcat(szTarget, szSub1);
  166.      pszReturnString = szTarget;
  167.   }
  168.  
  169.   return pszReturnString;
  170. }
  171.  
  172.  
  173. USHORT APIENTRY
  174. UtlMsgBox( HAB hab, HMODULE hmod, USHORT usMsgID,
  175.            USHORT fsStyle, BOOL fBeep)
  176. {
  177. USHORT  usRc;
  178. CHAR    szText[128];
  179. BOOL    fRc;
  180.  
  181.   fRc = UtlLoadMessage( hab
  182.                       , hmod
  183.                       , usMsgID
  184.                       , 128
  185.                       , (PSZ)szText);
  186.  
  187.   if ( fRc == API_FAILED )
  188.   {
  189.      WinAlarm( HWND_DESKTOP
  190.              , WA_ERROR);
  191.  
  192.      return MBID_ERROR;
  193.   }
  194.  
  195.   if (fBeep)
  196.      WinAlarm( HWND_DESKTOP
  197.              , WA_ERROR);
  198.  
  199.   usRc = WinMessageBox( HWND_DESKTOP
  200.                       , (HWND)0
  201.                       , (PSZ)szText
  202.                       , (PSZ)"Message Box"
  203.                       , IDD_MSGBOX
  204.                       , fsStyle);
  205.   return usRc;
  206.  
  207. }  // End of UtlMsgBox()
  208.  
  209.  
  210.  
  211. USHORT APIENTRY
  212. UtlUserMsgBox( PSZ     pszMsg
  213.              , PSZ     pszMsgBoxTitle
  214.              , USHORT  fsStyle
  215.              , BOOL    fBeep
  216.              , USHORT  usMsgID )
  217. {
  218.    USHORT usRc;
  219.  
  220.    if (fBeep)
  221.       WinAlarm( HWND_DESKTOP
  222.               , WA_ERROR);
  223.  
  224.    usRc = WinMessageBox( HWND_DESKTOP
  225.                        , (HWND)0
  226.                        , pszMsg
  227.                        , pszMsgBoxTitle
  228.                        , usMsgID
  229.                        , fsStyle);
  230.    return usRc;
  231. }
  232.  
  233.  
  234.  
  235. USHORT APIENTRY
  236. UtlDisplayDebug(PSZ pszText, PSZ pszTitle)
  237. {
  238.   USHORT usRc;
  239.  
  240.   usRc = WinMessageBox( HWND_DESKTOP
  241.                       , (HWND)0
  242.                       , pszText
  243.                       , pszTitle
  244.                       , 0
  245.                       , MB_ENTER);
  246.   return usRc;
  247. }  // End of UtlDisplayDebug()
  248.  
  249.  
  250.  
  251.  
  252.